package main

import (
	"fmt"
	"path"
	"strings"
)

func getRelativePath(a string, b string) string {
	var ret string = ""
	sa := strings.Split(path.Dir(a), "/")
	sb := strings.Split(path.Dir(b), "/")
	n := 0
	l := min(len(sa), len(sb))

	//n表示有前n个元素相同
	for {
		if n == l || sa[n] != sb[n] {
			break
		}
		n++
	}

	for i := 0; i < len(sb)-n; i++ {
		ret = ret + "../"
	}

	for i := n; i < len(sa); i++ {
		ret = ret + sa[i] + "/"
	}

	ret = ret + path.Base(a)
	return ret
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func main() {
	fmt.Println(getRelativePath("/a/b/c.php", "/a/d/e.php"))
}
